<script>
	import {
		mapMutations
	} from 'vuex';
	export default {
		methods: {
			...mapMutations(['login'])
		},
		onLaunch: function() {
			let userInfo = uni.getStorageSync('user') || '';
			let token = uni.getStorageSync('token') 
			if(!token){
				const routePath = ['/pages/user/register','/pages/user/login','/pages/user/register','/pages/user/forget',];
				let currentRoute = this.$route;
				console.log(currentRoute);
				if(routePath.indexOf(currentRoute.path)==-1){
					uni.reLaunch({
						url: "/pages/user/login"
					})
				}
				//不存在则跳转至登录页
				
			}
			if(userInfo.id){
				//更新登陆状态
				uni.getStorage({
					key: 'user',
					success: (res) => {
						this.login(res.data);
					}
				});
			}
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	@import '@/uni_modules/uni-scss/index.scss';
	/* #ifndef APP-NVUE */
	@import '@/static/customicons.css';
	// 设置整个项目的背景色
	.page {
		 padding-top: var(--status-bar-height);
		width: 100%;
		height: 100%;
	}

	/* #endif */
	.example-info {
		font-size: 14px;
		color: #333;
		padding: 10px;
	}
</style>
